package cn.bellychang.recursion.bobo.cl01AddLast;

/**
 * @author: bellychang
 * @date: 2020/2/13
 */
public class ArrayUtils {

    public static int sumByRecursion(int[] array) {
        if (array == null) {
            throw new IllegalArgumentException();
        }
        if (array.length == 0) {
            return 0;
        }
        if (array.length == 1) {
            return array[0];
        } else {
            int[] target = new int[array.length - 1];
            System.arraycopy(array, 0, target, 0, array.length - 1);
            return sumByRecursion(target) + array[array.length-1];
        }
    }
}
